import {createService } from "../request"
const rq = createService('/myapi')

// 获得图片分类列表，带分页
export function getImageCategores(page = 1, limit = 10, config) {
  return rq.get(
    `/admin/image_class/${page}`,
    {
      params: {
        limit
      },
    },
    config
  )
}

// 根据cateoryId 获得该分类下的图片列表，带分页
export function getImagesByCatogeryId(id, page = 1, limit = 10, config) {
  return rq.get(
    `/admin/image_class/${id}/image/${page}`,
    {
      params: {
        limit
      },
    },
    config
  )
}

// 根据cateoryId 修改分类
export function updateCatogeryById(id, name, order=50,config) {
  return rq.post(`/admin/image_class/${id}`,{
    name,
    order
  },config)
}

// 新增图片分类
export function addCatogery(name, order=50,config) {
  return rq.post(`/admin/image_class`,{
    name,
    order
  },config)
}

// 删除图片分类
export function deleteCatogery(id,config) {
  return rq.post(`admin/image_class/${id}/delete`,null,config)
}


// 删除选中的图片，ids = [491,492,493]
export function deleteImage(ids) {
  return rq.post(`/admin/image/delete_all`, {ids}, {
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 重命名选中的图片，id = 491
export function renameImage(id, name) {
  return rq.post(`/admin/image/${id}`, {name})
}

export const uploadImageAction = '/myapi/admin/image/upload'
